package gamebackend;


import framework.Color;
import framework.GraphicsWrapper;

public class LaserBeam {
	private static final Color INNER_COLOR = new Color(210, 225, 240);
	private static final Color FRINGE_COLOR = new Color(150, 210, 230);
	private static final double SPEED = 600 / 1000.0;
	private double my_height;
	private static final int DEFAULT_LIFE_TIME = 2000;
	private int my_width;
	private double my_x;
	private double my_y;
	private double my_xVelo;
	private double my_yVelo;
	private double my_lifeTime;
	private double my_health;
	public LaserBeam(final int the_width, final double the_x, final double the_y,
			final double the_xVelo, final double the_yVelo, final int timeSinceLast) {
		my_width = the_width;
		my_x = the_x;
		my_xVelo = the_xVelo;
		my_yVelo = Math.max(SPEED, the_yVelo);
		my_lifeTime = DEFAULT_LIFE_TIME;
		my_height = my_yVelo * timeSinceLast;
		my_y = the_y - my_height;
		my_health = 1;
	}
	

	public void step(int timeDelta, double cameraChange) {
		if (!isAlive()) {
			return;
		}
		my_x += my_xVelo * timeDelta;
		my_y += cameraChange - my_yVelo * timeDelta;
		
		
		my_lifeTime -= timeDelta;	
		
	}
	public void render(GraphicsWrapper g) {
		g.setColor(FRINGE_COLOR);
		g.fillRect((int) getLeft(), (int) getTop(), my_width, (int) my_height);
	}
	
	public void postRender(GraphicsWrapper g) {
		g.setColor(INNER_COLOR);
		g.fillRect((int) getLeft() + my_width / 4, (int) getTop(), my_width / 2, (int) my_height);
	}
	
	public void collide(final int collisions) {
		my_health -= collisions;
		
	}
	
	public boolean isAlive() {
		return my_lifeTime > 0 && my_health > 0;
	}
	public double getWidth() {
		return my_width;
	}
	public double getHeight() {
		return my_height;
	}
	public double getLeft() {
		return my_x - my_width / 2;
	}
	public double getTop() {
		return my_y + my_height / 2;
	}
	
}
